package com.payment.system.domain.wxpay;

import java.util.SortedMap;
import java.util.TreeMap;
import java.util.UUID;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "xml")
public class WxAppQueryReq {

	/** 应用ID */
	private String appId;
	/** 商户号 */
	private String mchId;
	/** 微信订单号 */
	private String transactionId;
	/** 商户订单号 */
	private String outTradeNo;
	/** 随机字符串 */
	private String nonceStr;
	/** 签名 */
	private String sign;

	
	
	public WxAppQueryReq() {
		super();
	}

	public WxAppQueryReq(String outTradeNo, String nonceStr) {
		this.appId = WxAppPayConfig.instance().appId;
		this.mchId = WxAppPayConfig.instance().mchId;
		this.nonceStr = nonceStr == null ? UUID.randomUUID().toString().trim().replaceAll(" ", "") : nonceStr;
		this.outTradeNo = outTradeNo;
		this.nonceStr = nonceStr;
		this.sign = createSign();
	}

	/**
	 * 签名
	 * 
	 * @return
	 */
	private String createSign() {
		SortedMap<String, Object> m = new TreeMap<>();
		m.put("appid", this.appId);
		m.put("mch_id", this.mchId);
		m.put("out_trade_no", this.outTradeNo);
		m.put("nonce_str", this.nonceStr);
		return WxPayUtil.sign(m);
	}

	@XmlElement(name = "appid")
	public String getAppId() {
		return appId;
	}

	public void setAppId(String appId) {
		this.appId = appId;
	}

	@XmlElement(name = "mch_id")
	public String getMchId() {
		return mchId;
	}

	public void setMchId(String mchId) {
		this.mchId = mchId;
	}

	@XmlElement(name = "transaction_id")
	public String getTransactionId() {
		return transactionId;
	}

	public void setTransactionId(String transactionId) {
		this.transactionId = transactionId;
	}

	@XmlElement(name = "out_trade_no")
	public String getOutTradeNo() {
		return outTradeNo;
	}

	public void setOutTradeNo(String outTradeNo) {
		this.outTradeNo = outTradeNo;
	}

	@XmlElement(name = "nonce_str")
	public String getNonceStr() {
		return nonceStr;
	}

	public void setNonceStr(String nonceStr) {
		this.nonceStr = nonceStr;
	}

	@XmlElement(name = "sign")
	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

}
